//
//  SecondViewController.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/31.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()<UIWebViewDelegate>
@property (nonatomic, retain)UIActivityIndicatorView *activityIndicator;


@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)requestByUrl:(NSString *)url
{
    
    //  创建webView
    UIWebView *webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //    //  设置代理
    //    webView.delegate = self;
    //  请求网址
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    //  加载网页
    [webView loadRequest:request];
    // 适配屏幕
    webView.scalesPageToFit = YES;
    webView.delegate = self;
    
    //  添加视图
    [self.view addSubview:webView];
    
}
// webView代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"网页开始加载的时候调用");
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [view setTag:108];
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.5];
    [self.view addSubview:view];
    
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];// 给边框
    [self.activityIndicator setCenter:view.center]; // 设置中心点
    [self.activityIndicator setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyleWhite)];// 设置类型
    [view addSubview:self.activityIndicator]; // 添加视图
    [self.activityIndicator startAnimating]; // 开始显示
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    NSLog(@"网页加载完成的时候");
    [self.activityIndicator stopAnimating];//停止滚轮
    // 在这里去掉加载滚轮的小幅哦
    UIView *view = (UIView *)[self.view viewWithTag:108];
    // 取出滚轮视图
    [view removeFromSuperview];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
